package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    @AnnoLog(value = "用户新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addUser(@RequestBody Map<String, Object> dataParam) {
        return userService.addUser(dataParam);
    }

    @AnnoLog(value = "用户修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateUser(@RequestBody Map<String, Object> dataParam) {
        return userService.updateUser(dataParam);
    }

    @AnnoLog(value = "用户删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteUser(@RequestBody Map<String, Object> dataParam) {
        return Result.success(userService.deleteUser((String) dataParam.get("ids")));
    }

    @AnnoLog(value = "用户列表")
    @PostMapping("/list")
    public Result<?> userList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(userService.getUserPage(queryParam));
    }

}